<?php
//简单管理页面范例，在你的管理页面引用coresection/checkA.php就OK，
//当然，不要忘了添加注销登录的链接
include_once '../common/script/check_session.php';
?>


<?
if(isset($_REQUEST['sys_part']))
{
$system_part = $_REQUEST ['sys_part'];	
}


?>



<?
include_once("../../config_controller.php");
$host = $_SERVER['HTTP_HOST']; //取得进入所输入的域名
$theme_folder = host_theme($host);

include_once '../../front/' . $theme_folder . '/connection.php';include_once '../common/script/check_session.php';

?>

<?php include_once("function.php"); ?>
<?php include "../../front/" . $theme_folder . "/config.php"; ?>

<?php include_once($_SERVER['DOCUMENT_ROOT']."/controller/common/script/site-function.php"); ?>

<?
//20190601 取消这个文件include_once("detail-function.php")，后来发现，分类的数据，靠这个函数去获取。;
include_once("detail-function.php");
$detail=select_one_line_all_items($table_Prefix."detail","nid = '".$_REQUEST ['nid']."'");

$temp_erweima = json_decode($detail['erweima'],true);

$temp_erweima_link = explode('attr=',$temp_erweima['link']);

$select_link_attr = array();

if($temp_erweima_link[1]){
	
	foreach(explode($temp_erweima['link_code'],$temp_erweima_link[1]) as $val){
		$select_link_attr[] = $val;
	}
	
}

foreach($temp_erweima as $key=>$val){
	
	$erweima[] = $key;
}
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php include_once('../modules/head.php'); ?>



  
</head>

<body>

<div id="topbar">
    <!--TopBar端點01-->
    <?php include '../modules/topbar.php'; ?>
    <!--TopBar端點02-->
</div>

<div id="container">
<!--Container端點01-->
<div id="maincontent">
<!--maincontent端點01-->

<div id="sidebar">
    <?php include '../modules/sidebar.php'; ?>
</div>


<div id="content">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
        <legend><h1>批量二维码设置 </h1></legend>
    </fieldset>

<div class="detail-box <? echo $system_part ?>">



<ul>

<form id="detail_detail_form" method="post"
      class="layui-form  layui-form-pane"
      action="erweima-all-edit-function.php?sys_part=<? echo $system_part ?>"
      name="uploadfile">

	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;" id="content4">
            <legend>关联板块</legend>
        </fieldset>
        <br/>
     
	<div class="">
                    
                      <div class="layui-form-item">
                        <label class="layui-form-label">搜索产品</label>
                        <div class="layui-input-block">
                         	<input type="text" name="title" required  lay-verify="required" placeholder="请输入产品标题" autocomplete="off" class="layui-input search_product">
                          <br />
                          <br />
                          <div class="layui-btn layui-btn-sm layui-btn-warm search_btn">搜索相关内容</div> 
                        </div>
                        
                      </div>
                      <div class="">
    
                            <div id="test4" class="demo-transfer"></div>
                          
                      </div>
                </div>


    <fieldset class="layui-elem-field layui-field-title" id="content1" style="margin-top: 30px;">
        <legend>基本信息</legend>
    </fieldset>

    <blockquote class="layui-elem-quote">基本信息多数是对外使用的资料，请细心填写。</blockquote>
    <br/>









    <li class="layui-form-item publish">
        <label class="layui-form-label">设置链接：</label>
        
        <div class="layui-input-block">
            <input type="checkbox" lay-filter="sub_attr" class="attr_url" name="attr[url]"   title="当前链接" >
          
        </div>
        
        <em class="explain"></em>
        
    </li>

    <li class="layui-form-item publish">
        <label class="layui-form-label">设置参数：</label>
        
        <div class="layui-input-block">
          
            <input type="checkbox" lay-filter="sub_attr" class="attr_attr" name="attr[model]" title="型号">
            <input type="checkbox" lay-filter="sub_attr" class="attr_attr" name="attr[introduce]" title="简介" >
            <input type="checkbox" lay-filter="sub_attr" class="attr_attr" name="attr[name]" title="名称" >
        </div>
        
        <em class="explain"></em>
        
    </li>




    <li class="layui-form-item link"><label class="layui-form-label">跳转地址：</label>

        <div class="layui-input-block"><input type="text"  class="layui-input attr_link" name="attr[link]"    value=""></div><em class="explain"></em>
    </li>
    <li class="layui-form-item link"><label class="layui-form-label">参数分隔符：</label>

        <div class="layui-input-block"><input type="text"  class="layui-input attr_link_code" name="attr[link_code]"    value="|"></div><em class="explain"></em>
    </li>
    <li class="layui-form-item publish">
        <label class="layui-form-label">跳转参数：</label>
        
        <div class="layui-input-block">
          
            <input type="checkbox" lay-filter="link_attr" class="link_attr" name="link_attr[model]"   title="型号" >
            <input type="checkbox" lay-filter="link_attr" class="link_attr" name="link_attr[introduce]" title="简介" >
            <input type="checkbox" lay-filter="link_attr" class="link_attr" name="link_attr[name]"  title="名称">
        </div>
        
        <em class="explain"></em>
        
    </li>
    
    
    



    <div class="function">
    	<button class="layui-btn " lay-submit lay-filter="formSub">立即提交</button>
       
        <input type="reset" class="layui-btn" value="重置"/>
		
        <input name="sys_part" type="hidden" value="<? echo $system_part ?>"/>
       
        <input type="hidden" name="detail_attr" id="detail_attr" />
        <a href="javascript:;" class="layui-btn layui-bg-red layui-icon layui-icon-top go_top"></a>
    </div>
		

</form>
</ul>


</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>


<?php include  ROOT_PATH_."/controller/modules/footer.php"; ?>

<script type="text/javascript">

$('.search_btn').click(
	function(){
		
		/*$.each($("input[name='article_type[]']"), function(i,val){ 
			
			 alert(val.name);
			 alert(val.value);  
		});*/
		 search_val = $('.search_product').val();
		 
		
			$.ajax({
			type:"POST",
			url:"ajax_search_product.php?act=search_product",
			dateType:"json",
			data:{"val":search_val},
			dataType:"json",
			beforeSend: function () {
				
				$('.search_btn').attr({ disabled: "disabled" });
				
			   index =  layer.msg('正在查询中，请稍等', {
				  icon: 16,
				  shade:true,
				  time:10000,
				  shade: [0.8, '#393D49']
				},function(){
					
				});
				
			
			 }, 
			success:function(data){				
				if(data.error == 1){
					
					var msg_box = layer.msg(data.message, {
					  icon: 5,
					  shade:true,
					  time:1000,
					  shade: [0.8, '#393D49']
					});
					//
				}	
				else{
					layui.use(['transfer', 'layer', 'util'], function(){
					  var $ = layui.$
					  ,transfer = layui.transfer
					  ,layer = layui.layer
					  ,util = layui.util;
					  
					   
					  //模拟数据
					  var data1 = data.content
					  
					   transfer.reload('detail_attr_list', {
						  data: data1
						});
						
					});
					
				}
			},
			complete: function (XHR, TS) {layer.close(index);    XHR = null ; $('.search_btn').removeAttr("disabled"); } ,
			
		})

	}
)




$(document).ready(function(e) {
    

  
 layui.use(['transfer', 'layer', 'util', 'form'], function(){
	  var $ = layui.$
	  ,transfer = layui.transfer
	  ,layer = layui.layer
	  ,util = layui.util
	  ,form = layui.form;
	   
	
	var data1 = <?php echo $json_data;?>  //显示搜索框
	transfer.render({
			elem: '#test4'
			,showSearch: true
			,height:300
			,width:600
			,data: data1
			,title: ['全选', '全选']
			
			
			,id: 'detail_attr_list'
			,value: [<?php echo $detail_relation_list;?>]
	}) 
	
	
						
						
	  form.on('submit(formSub)', function(data){
		 
		  
		  var getData = transfer.getData('detail_attr_list'); 
		  
		  json_data = JSON.stringify(getData); 
		 
		  $('#detail_attr').val(json_data)
		  
		  attr_url =  $(".attr_url").prop("checked")
		  attr_attr =  $(".attr_attr").prop("checked") 
		  
		  attr_link = $(".attr_link").val() 
		  
		  if(json_data == '[]'){
				alert("请选择数据")
			  return false;	 
		  }
		  
		  if(attr_url == true || attr_attr == true || attr_link != ''){
			
		  }
		  else{
			  alert("请选择其中一项类型")
			  return false;	 
	      }
		 
		 
	  })
	  
	});

  
});

$(document).ready(function(e) {
    
	var attr_link_content = <?php echo isset($temp_erweima_link[1]) ? "'".$temp_erweima_link[1]."'" :"''" ?>;
	var attr_link_bak = $('.attr_link').val()
	var attr_link_code = $('.attr_link_code').val()
	
	
	
	layui.use('form', function(){
	  var form = layui.form;
	  	
		$('.attr_link_code').change(
			function(){
				
				attr_link_code = $(this).val()
			
				
				attr_link = $('.attr_link').val()
						
				reg1 = RegExp('attr=');
						
				is_has_attr_code = reg1.test(attr_link);
				
				if(is_has_attr_code == true){
					
					new_attr_link = getCaption(attr_link,0,'?');
						
					$('.attr_link').val(new_attr_link)
					
					$('.link_attr').attr('checked', false);
					attr_link_bak = new_attr_link;
					attr_link_content = '';
					form.render();
				}
			}
		)
		
	  	form.on('checkbox(sub_attr)', function(data){
		  now_name = data.elem.name; //得到checkbox原始DOM对象
		  now_check = data.elem.checked; //是否被选中，true或者false
			if(now_name == 'attr[url]' && now_check == true){
				$('.attr_attr').attr('checked', false);
				$('.attr_link').attr("readonly","readonly")
				$('.link_attr').attr('checked', false);
			}
			else if(now_name == 'attr[url]' && now_check == false){
				$('.attr_attr').attr('checked', false);
				$('.attr_link').attr("readonly",false)
				$('.link_attr').attr('checked', false);
			}
			
			if(now_name != 'attr[url]' && now_check == true){
				$('.attr_url').attr('checked', false);
				$('.attr_link').attr("readonly","readonly")
				$('.link_attr').attr('checked', false);
			}
			else if(now_name != 'attr[url]' && now_check == false){
				$('.attr_url').attr('checked', false);
				$('.attr_link').attr("readonly",false)
				$('.link_attr').attr('checked', false);
			}
			
			form.render();
		});        
		
		$('.attr_link').click(function(){
			$('.attr_url').attr('checked', false);
			$('.attr_attr').attr('checked', false);
			
			$('.link_attr').attr('checked', false);
			$('.attr_link').attr("readonly",false)
			form.render();
		})
		
		form.on('checkbox(link_attr)', function(data){
		 	
			$('.attr_url').attr('checked', false);
			$('.attr_attr').attr('checked', false);
			
			
			attr_link = $('.attr_link').val()
					
			reg1 = RegExp('attr=');
					
			is_has_attr_code = reg1.test(attr_link);
					
		  	now_check = data.elem.checked; //是否被选中，true或者false
			if( now_check == true){
				
				
				if(attr_link == ''){
					layer.msg('请填写网址内容');
					$('.link_attr').attr('checked', false);
					form.render();
					return
				}
				
				
				$('.attr_attr').attr('checked', false);
				$('.attr_url').attr('checked', false);
			}
			
			form.render();
		});
	});
	
});



function getCaption(obj,state,code) {
    var index=obj.lastIndexOf(code);
    if(state==0){
        obj=obj.substring(0,index);
    }else {
        obj=obj.substring(index+1,obj.length);
    }
    return obj;
}

</script>

</body>
</html>
